package com.yixia.web.controller;

import com.yixia.common.core.domain.AjaxResult;

import com.yixia.common.core.domain.entity.SysUser;
import com.yixia.common.utils.JwtUtils;
import com.yixia.system.service.system.SysMenuService;
import com.yixia.system.service.system.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private SysMenuService sysMenuService;


    @GetMapping("/user/list")
    @PreAuthorize("hasRole('ROLE_admin')")
    public AjaxResult userList(@RequestHeader(required = false) String token) {
        Map<String, Object> resutMap = new HashMap<>();
        List<SysUser> userList = sysUserService.list();
        resutMap.put("userList", userList);
        return AjaxResult.success(resutMap);
    }

    @GetMapping("/login")
    public AjaxResult login() {
        String token = JwtUtils.genJwtToken("java1234");
        return AjaxResult.success().put("token", token);
    }


   /* *//**
     * 获取路由信息
     *
     * @return 路由信息
     *//*
    @GetMapping("getRouters")
    public R getRouters()
    {
        Long userId = 1L;
        List<SysMenu> menus = sysMenuService.selectMenuTreeByUserId(userId);
        List<RouterVo> routerVos = sysMenuService.buildMenus(menus);

        return R.ok(routerVos);
    }*/
}
